package com.zyh.buffer;

public class StringBufferDemo1 {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer("hello java");
        //添加
        sb.append("world").append(3.14).append(false);
//        sb.append(3.14);
//        sb.append(false);
        System.out.println("sb = " + sb);//sb = hello javaworld3.14false

        //删除
        sb.delete(0,sb.indexOf(" ")+1);
        System.out.println("sb = " + sb);//sb = javaworld3.14false
        sb.deleteCharAt(0);
        System.out.println("sb = " + sb);//sb = avaworld3.14false

        //修改
        sb.replace(0,3,"hello ");
        System.out.println("sb = " + sb);//sb = hello world3.14false
        //修改单个字符
        sb.setCharAt(0,'H');
        System.out.println("sb = " + sb);//sb = Hello world3.14false

        //查找
        int index = sb.indexOf("H", 2);
        System.out.println("index = " + index);//index = -1

        //反转
        sb.reverse();
        System.out.println("sb = " + sb);//sb = eslaf41.3dlrow olleH

        //setLength
        sb.setLength(4);
        System.out.println("sb = " + sb);//sb = esla

        //length
        int length = sb.length();
        System.out.println("length = " + length);//length = 4

        //截取
        String substring = sb.substring(1);
        System.out.println("substring = " + substring);//substring = sla


    }
}
